﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DataModel;
using BasicDataManagement;

namespace Preproduce
{
    /// <summary>
    /// AddPreproduceWindowxaml.xaml 的交互逻辑
    /// </summary>
    public partial class AddPreproduceWindowxaml : Window
    {
        IOpertation op;
        public PreproduceObject pre;

        public AddPreproduceWindowxaml()
        {
            InitializeComponent();
            op = OperationFactory.Create();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            fdNameCB.ItemsSource = new ObservableCollection<string>(op.LoadFixedDishItemName());
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (fdNameCB.SelectedIndex == -1 || valueTB.Text.Equals(""))
            {
                MessageBox.Show("请填写完整信息");
                return;
            }
            else
            {
                try
                {
                    pre = new PreproduceObject()
                    {
                        FixedDishName = fdNameCB.Text,
                        Value = Convert.ToInt32(valueTB.Text)
                    };
                    this.DialogResult = true;
                    this.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("填写信息有误");
                    return;
                }
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }
    }
}
